package stack;

import java.util.ArrayList;
import java.util.Stack;

public class dailyTemperatures {
    public int[] dailyTemperatures(int[] temperatures) {
        int[] result = new int[temperatures.length];
        Stack<Integer> integers = new Stack<>();
        for (int i = 0; i < temperatures.length; i++) {
            while (!integers.isEmpty() && temperatures[i] > temperatures[integers.peek()]){
                result[integers.peek()] = i - integers.peek();
                integers.pop();
            }
            integers.push(i);
        }
        return result;
    }
}
